/**
 * 
 */
package cn.biplam.back.sql.dml;

import cn.biplam.common.wrapper.ErrorMessage;

/**
 * Delete语义模型
 * 简单模式用法：<BR>
 * <P>new Delete("表物理名称");</P>
 * <P>this.setWhere(String 过滤表达式);[可选]</P>
 * <P>String this.getSimpleSql();</P>
 * 
 * @author 	WangSong 2009-6-11 下午02:05:02
 * @version 1.0
 */
public class Delete extends DmlBase {

	private String sWhere;
	
	public Delete(String tableName) {
		super("Delete", tableName);
	}

	/**
	 * 设置简单Delete语句的Where条件
	 * @param where
	 * @throws ErrorMessage 
	 */
	public void setWhere(String where) throws ErrorMessage{
		if(this.dmlType==Dml_Type.Complex){
			throw new ErrorMessage("Complex Delete disallow put where String.");
		}
		this.sWhere=where;
	}

	/**
	 * 
	 * @return
	 * @throws ErrorMessage
	 */
	@Override
	public String getSimpleSql() throws ErrorMessage {
		StringBuilder sb = new StringBuilder();
		sb.append("delete from ");
		sb.append(this.sTableName);
		if(this.sWhere!=null){
			sb.append(" where ");
			sb.append(this.sWhere);
		}
		return sb.toString();
	}
	
}
